/**
 * input:a positive integer 
 * output:all its smallest factors in decreasing order
 * use the stackofintegers class to store the factors
 * and retrieve and display them in reverse order
 */

/**
 * @author XU Fazheng  
 * @ID 204603100507    
 * @CLASSCOMP 1010    
 * @date 2020/12/12
 * @version 1.0
 */
import java.util.*;
import java.lang.*;
public class StackOfIntegers {
	//StringBuilder s = new StringBuilder(24);没有必要
	private int num;
	private int maxn;
	private int cot=0;
	/**
	 * 
	 */
	public StackOfIntegers(int num) {
		// TODO Auto-generated constructor stub
		this.num=num;	
		this.maxn = (int)Math.sqrt(num);
		
	}
	
	private int[] findFactor() {
		int visit[] = new int[maxn*2];
		int factor[] = new int[maxn*2];
		int p[] = new int[maxn*2];
		Arrays.fill(p, 0);
		Arrays.fill(visit, 0);
		for(int i=2;i<=maxn;i++) {
			if(visit[i]==0) {
				p[++p[0]]=i;
			//	System.out.print(factor.length);
				while(num%i==0) {
					num/=i;
					factor[cot]=i;
					cot++;
					
				}
			}
			for(int j=1;j<=p[0]&&i*p[j]<=maxn;j++) {
				visit[i*p[j]]=1;
				if(i%p[j]==0)break;
			}
		}
		return factor;
	}
	public void ReverseOrder() {
		int answer[] = findFactor();
		for(int i=cot-1;i>=0;i--) {
			System.out.printf("%d,",answer[i]);
		}
	}
	private int[] prime() {
		int visit[] = new int[maxn*2];
		int p[] = new int[maxn*2];
		Arrays.fill(visit, 0);
		Arrays.fill(p, 0);
		for(int i=2;i<=maxn;i++) {
			if(visit[i]==0) {
				p[++p[0]]=i;
			}
			for(int j=1;j<=p[0]&&i*p[j]<=maxn;j++) {
				visit[i*p[j]]=1;
				if(i%p[j]==0)break;
			}
		}
		return p;
	}
	public void printPrime() {
		int p[] = prime();
		for(int i=p[0];i>=1;i--) {
			if(i==1) {
				System.out.print(p[i]);
				break;
			}
			System.out.printf("%d,",p[i]);
		}
	}
}
